package com.lyncs.ods.modules.txn.service;

import com.lyncs.ods.common.api.CommonPage;
import com.lyncs.ods.constant.LyncsOdsConstant;
import com.lyncs.ods.modules.txn.model.CommonTxnSubItem;
import com.lyncs.ods.modules.txn.model.TxnCommonInfo;
import com.lyncs.ods.modules.txn.model.TxnEditLog;
import com.baomidou.mybatisplus.extension.service.IService;
import com.lyncs.ods.resp.TxnEditLogResp;
import org.apache.commons.lang3.tuple.Pair;

import java.util.List;
import java.util.Map;
import java.util.function.Supplier;

/**
 * <p>
 * ods编辑历史记录 服务类
 * </p>
 *
 * @author alex
 * @since 2022-04-09
 */
public interface TxnEditLogService extends IService<TxnEditLog> {

    /**
     * 保存操作日志
     *
     * @param oldEntity   old
     * @param newEntity   new
     * @param type        type
     * @param refId       type id
     * @param logId       logId
     * @param companyFunc companyName
     * @param userFunc    userName
     * @param <T>         object class
     */
    <T extends TxnCommonInfo> void saveLog(T oldEntity, T newEntity, LyncsOdsConstant.TxnType type, Long refId, Long logId, Supplier<String> companyFunc, Supplier<String> userFunc);

    /**
     * 保存 sku/账款 操作日志
     *
     * @param insertSubItems new
     * @param deleteSubItems delete
     * @param updateSubItems update
     * @param refId          type id
     * @param logId          logId
     * @param companyFunc    companyName
     * @param userFunc       userName
     * @param nameMap        name map
     * @param <T>            object class
     */
    <T extends CommonTxnSubItem> void saveSubItemLog(List<T> insertSubItems, List<Long> deleteSubItems, List<Pair<T, T>> updateSubItems, LyncsOdsConstant.TxnType type, LyncsOdsConstant.TxnEditType editType, LyncsOdsConstant.TxnType subItemType, Long refId, Long logId, Supplier<String> companyFunc, Supplier<String> userFunc, Map<Long, String> nameMap);

    /**
     * 分页获取日志
     *
     * @param type     type
     * @param refId    refId
     * @param page     page
     * @param pageSize pageSize
     * @return logs
     */
    CommonPage<TxnEditLogResp> getEditLog(Integer type, Long refId, Integer page, Integer pageSize);
}
